/*
Copyright (C) 2011  Wade Chatam

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.nadi.noda.islamicpuzzle;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;
import com.nadi.noda.islamicpuzzle.R;
import com.nadi.noda.tech.AnalyticUtils;
import com.nadi.noda.tech.AnalyticUtils.TrackerName;

/**
 * This is the introductory Activity for the IslamicBuzzle application. It gives the user some basic options for starting a new game and
 * learning more about the application.
 * 
 * @author nadi.noda
 * 
 */
public final class IntroActivity extends Activity implements OnClickListener {
	public static final int DIALOG_ABOUT_ID = 0;
	public Context context;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		context = getApplicationContext();
		setContentView(R.layout.intro);
		findViewById(R.id.play_button).setOnClickListener(this);
		findViewById(R.id.settings_button).setOnClickListener(this);
		findViewById(R.id.about_button).setOnClickListener(this);
		
		// Analytic
		Tracker tracker = AnalyticUtils.getTracker(context, TrackerName.APP_TRACKER);
		tracker.setScreenName("IslamicBuzzle");
		tracker.send(new HitBuilders.AppViewBuilder().build());
	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.play_button:
			Intent iPlay = new Intent(this, PuzzleActivity.class);
			startActivity(iPlay);
			break;
		case R.id.settings_button:
			Intent iSetting = new Intent(this, SettingsActivity.class);
			startActivity(iSetting);
			break;
		case R.id.about_button:
			showDialog(DIALOG_ABOUT_ID);
			break;
		}
	}

	@Override
	protected Dialog onCreateDialog(int id) {
		Dialog dialog;
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		switch (id) {
		case DIALOG_ABOUT_ID:
			builder.setMessage(R.string.about_text).setCancelable(false).setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();
				}
			});
			dialog = builder.create();
			break;
		default:
			dialog = null;
		}
		return dialog;
	}
}
